// ----------------------------------
// RSDK Project: Sonic 2
// Script Description: WFZ Setup Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// ========================
// Aliases
// ========================

private alias object.value1 : object.palCycleTimer
private alias object.value2 : object.palCycleTablePos
private alias object.value3 : object.paletteTimer
private alias object.value4 : object.palCycle1Timer


// Player Aliases
private alias object.gravity : player.gravity
private alias object.animation : player.animation
private alias object.xvel : player.xvel
private alias object.yvel : player.yvel
private alias object.speed : player.speed
private alias object.up : player.up
private alias object.down : player.down
private alias object.ypos : player.ypos

// Game Modes
private alias 0 : MODE_NOSAVE
private alias 1 : MODE_SAVEGAME
private alias 2 : MODE_TIMEATTACK

// Tracks
private alias 0 : TRACK_STAGE
private alias 1 : TRACK_ACTFINISH
private alias 2 : TRACK_INVINCIBLE
private alias 3 : TRACK_CONTINUE
private alias 4 : TRACK_BOSS
private alias 5 : TRACK_GAMEOVER
private alias 6 : TRACK_DROWNING
private alias 7 : TRACK_SUPER

// Reserved object slots
private alias 10 : SLOT_ZONESETUP
private alias 25 : SLOT_MUSICEVENT_CHANGE

// Music Events
private alias  0 : MUSICEVENT_FADETOBOSS
private alias  1 : MUSICEVENT_FADETOSTAGE
private alias  2 : MUSICEVENT_TRANSITION

private alias 0 : MUSICEVENT_FLAG_NOCHANGE
private alias 1 : MUSICEVENT_FLAG_SPEEDUP
private alias 2 : MUSICEVENT_FLAG_SLOWDOWN

// Music Loops
private alias 99874 : MUSIC_LOOP_DEZ
private alias 80074 : MUSIC_LOOP_WFZ_F

private alias 38679 : MUSIC_LOOP_INV
private alias 30897 : MUSIC_LOOP_INV_F


// ========================
// Function Declarations
// ========================

reserve function WFZSetup_State_Clinging

reserve function WFZSetup_SpeedUpMusic
reserve function WFZSetup_SlowDownMusic


// ========================
// Static Values
// ========================

public value WFZSetup_scrollVelocity.x = 0
public value WFZSetup_scrollVelocity.y = 0

public value WFZSetup_hPropellerFrame = 0
public value WFZSetup_hPropellerTimer = 0
public value WFZSetup_vPropellerFrame = 0
public value WFZSetup_vPropellerTimer = 0


// ========================
// Tables
// ========================

private table WFZSetup_palCycleTable
	0xE080E0, 0xB44890, 0x90246C, 0x6C0048
	
end table


// ========================
// Function Definitions
// ========================

// ========================
// Events
// ========================

event ObjectUpdate
	object.palCycleTimer++
	if object.palCycleTimer == 4
		object.palCycleTimer = 0
                RotatePalette(0, 112, 119, true)
	end if

	WFZSetup_hPropellerFrame = WFZSetup_hPropellerTimer
	WFZSetup_hPropellerFrame >>= 1
	WFZSetup_hPropellerTimer++
	WFZSetup_hPropellerTimer %= 12

	WFZSetup_vPropellerFrame = WFZSetup_vPropellerTimer
	WFZSetup_vPropellerFrame >>= 1
	WFZSetup_vPropellerTimer++
	WFZSetup_vPropellerTimer %= 6
end event

	SpeedUpMusic = WFZSetup_SpeedUpMusic
	SlowDownMusic = WFZSetup_SlowDownMusic

	animalType1 = TypeName[Locky]
	animalType2 = TypeName[Wocky]

	// Reset the boss flash color to just be a solid black for now
	SetPaletteEntry(0, 196, 0x000000)

	object[SLOT_ZONESETUP].type = TypeName[WFZ Setup]
	object[SLOT_ZONESETUP].priority = PRIORITY_ACTIVE

	WFZSetup_scrollVelocity.x = 0
	WFZSetup_scrollVelocity.y = 0
	
	WFZSetup_hPropellerFrame = 0
	WFZSetup_hPropellerTimer = 0
	WFZSetup_vPropellerFrame = 0
	WFZSetup_vPropellerTimer = 0
	
	// This level has a special cutscene and all for the main game, remove Animal Capsules outside of TA so that we can watch it
	foreach (TypeName[Animal Prison], arrayPos0, ALL_ENTITIES)
		if options.gameMode != MODE_TIMEATTACK
			ResetObjectEntity(arrayPos0, TypeName[Blank Object], 0, 0, 0)
		end if
	next
end event


// ========================
// Editor Events
// ========================

event RSDKDraw
	DrawSprite(0)
end event


event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
	
	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end event
